<template>
  <div>
    <router-link class="heander-abs" tag='div' to='/' v-show="showAbs"><div class="iconfont back-icon">&#xe624;</div></router-link>
    <div class="header" v-show='!showAbs' :style="opacityStyle">
      <router-link to="/">
        <div class="iconfont header-back">&#xe624;</div>
      </router-link>
      景点详细信息
    </div>
  </div>
</template>

<script>
export default {
  name: 'DetailHeader',
  data () {
    return {
      showAbs: true,
      opacityStyle: {
        opacity: 0
      }
    }
  },
  methods: {
    scrollChange () {
      const scrollTop = document.documentElement.scrollTop
      console.log(scrollTop)
      if (scrollTop > 50) {
        let opacity = scrollTop / 100
        opacity = opacity > 1 ? 1 : opacity
        this.opacityStyle = { opacity }
        this.showAbs = false
      } else {
        this.showAbs = true
      }
    }
  },
  activated () {
    window.addEventListener('scroll', this.scrollChange)
  },
  deactivated () {
    window.removeEventListener('scroll', this.scrollChange)
  }
}
</script>

<style lang='stylus' scoped>
  @import '~styles/varibles.styl'
  .heander-abs
    position absolute
    left .2rem
    top .2rem
    width .8rem
    height .8rem
    border-radius .4rem
    text-align center
    line-height .8rem
    background: rgba(0 ,0 ,0, .6)
    .back-icon
      color: #fff
      font-size: .4rem
  .header
    position fixed
    z-index 2
    left 0
    right 0
    top 0
    height: $headerHeight
    overflow: hidden
    line-height: $headerHeight
    text-align: center
    color: #fff
    background: $bgColor
    font-size: .32rem
    .header-back
      width: .64rem
      text-align: center
      font-size .4rem
      position: absolute
      top 0
      left: 0
      color: #fff
</style>
